﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Configuration;

namespace IronOne.SalesOne.DataObjects
{
    public static class DataContextFactory
    {
        private static readonly string _connectionString;
        private static readonly MappingSource _mappingSource;


        static DataContextFactory()
        {
            string connectionStringName = ConfigurationManager.AppSettings.Get("ConnectionStringName");
            _connectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
            

            DataContext context = new SODataDataContext(_connectionString);
            _mappingSource = context.Mapping.MappingSource;
        }

        public static SODataDataContext CreateContext()
        {
            return new SODataDataContext(_connectionString, _mappingSource);
        }
    }
}
